

class NeighborRouter(object):
    total_number = 0

    def __init__(self):
        self.interfaces = []
        self.index = self.total_number
        NeighborRouter.total_number += 1

class Interface(object):
    def __init__(self, index, adj_router):
        self.index = index
        self.adj_router = adj_router


def gen_tree_p2p_topo(routers, max_intf_num):
    next_idle_router_index = 1
    for index, router in enumerate(routers):
        child_intf_num = max_intf_num - 1 if index else max_intf_num
        for intf_index in range(child_intf_num):
            if next_idle_router_index < len(routers):
                child = routers[next_idle_router_index]
                intf = Interface(len(router.interfaces), child)
                router.interfaces.append(intf)
                intf = Interface(len(child.interfaces), router)
                child.interfaces.append(intf)
                next_idle_router_index += 1
            else:
                return

if __name__ == '__main__':
    routers = [NeighborRouter() for i in range(10)]
    gen_tree_p2p_topo(routers, 3)